Skip to content

Fix a couple AST mistakes caught while porting the parser to Rust #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2017

Conversation

zbraniecki
Copy link
Collaborator

Minor improvements to the parser and aligning error messages with the actual code. Found during porting to Rust.

@zbraniecki zbraniecki requested a review from stasm June 25, 2017 08:17
Copy link
Contributor

@stasm stasm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these changes don't look right without understanding more about them. My questions are inline.

@@ -210,13 +210,6 @@ export class Section extends Entry {
}
}

export class Function extends Identifier {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this doesn't look right. Function is a valid ASDL production: https://github.com/projectfluent/fluent/blob/a9fb740ecbf9326a484b812800f62a338a43f7da/spec/fluent.asdl#L72

Instead, I think when we create a CallExpression, we should ensure that the callee field is a Function, not just an Identifier:

return new AST.CallExpression(literal.id, args);

@@ -212,7 +212,7 @@ export default class FluentParser {
tags = this.getTags(ps);
}

if (pattern === undefined && attrs === undefined && tags === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing the tags check here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding was that we don't accept messages with just tags (they have to have attrs or value). Am I wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you're right! That's a good point. The EBNF confirms this: https://github.com/projectfluent/fluent/blob/master/spec/fluent.ebnf#L43. Thanks for correcting me.

@zbraniecki
Copy link
Collaborator Author

updated to your feedback!

@@ -566,7 +566,10 @@ export default class FluentParser {

ps.expectChar(')');

return new AST.CallExpression(literal.id, args);
return new AST.CallExpression(
new AST.Function(literal.id.name),
Copy link
Contributor

@stasm stasm Jun 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an assertion to make sure literal.id.name conforms to the EBNF? It should only accept [A-Z_?-]+.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would you like the assertion to look like? A regexp?

@zbraniecki
Copy link
Collaborator Author

Re-requesting review because of the added check in the parser and test.

I decided not to add ? because it's not supported anywhere in the parser, I raised a suggestion to remove it from the spec - projectfluent/fluent#49 - and if this suggestion will get rejected, we will have to update all parsers, so we can fix it here then as well.

@zbraniecki zbraniecki merged commit 41ea09d into projectfluent:master Jun 29, 2017
@stasm
Copy link
Contributor

stasm commented Aug 21, 2017

@zbraniecki Would you like to port this to python-fluent? It would help me finish projectfluent/python-fluent#17.

zbraniecki pushed a commit to projectfluent/python-fluent that referenced this pull request Aug 22, 2017
@zbraniecki
Copy link
Collaborator Author

PR: projectfluent/python-fluent#18

zbraniecki added a commit to projectfluent/python-fluent that referenced this pull request Aug 22, 2017
@zbraniecki zbraniecki deleted the ast-fixed branch December 12, 2017 04:43
eemeli pushed a commit to mozilla/fluent-migrate that referenced this pull request May 16, 2023
eemeli pushed a commit to mozilla/fluent-migrate that referenced this pull request May 16, 2023
jfx2006 pushed a commit to jfx2006/tb-fluent-migrate that referenced this pull request Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants